//
//  ViewController.swift
//  ScanBleBtDeviceMac
//
//  Created by Caijinglong on 2017/9/11.
//  Copyright © 2017年 ScanBleBtDeviceMac. All rights reserved.
//

import Cocoa
typealias Byte = UInt8

class ViewController: NSViewController {

    var helper = PrinterHelper.shared
    var weightHelper = WeightHelper.shared
    
    @IBOutlet weak var receiveText: NSTextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override var representedObject: Any? {
        didSet {
        // Update the view, if already loaded.
        }
    }

    @IBAction func conn(_ sender: Any) {
//        helper.conn(deviceName: "QSprinter")
        weightHelper.scanForName(name: "BJJY-1588")
        weightHelper.delgate = self
    }

    @IBAction func print(_ sender: Any) {
        _ = helper
            .subTitle("测试标题")
            .newLine()
            .alignLeft()
            .sendMsg(msg: "左部文字")
            .newLine()
            .alignCenter()
            .sendMsg(msg: "居中文字")
            .newLine()
            .alignLeft()
            .boldOn()
            .sendMsg(msg: "加粗文字")
            .boldOff()
            .newLine()
            .setFontSize(size: 2)
            .sendMsg(msg: "文字大小2")
            .newLine()
            .setFontSize(size: 3)
            .sendMsg(msg: "文字大小3")
            .newLine()
            .setFontSize(size: 0)
            .printDivider()
            .newLine(lines: 3)
            .printDivider()
            .newLine()
            .sendQrcode(qrcode: "Test123")
            .startPrint()
    }
}
extension ViewController:WeightResultDelegate{
    func weightResult(weight: String) {
        NSLog("weight = \(weight)")
        receiveText.stringValue = weight
    }
}
